/**
 * @Company:中享思途   
 * @Title:CatalogManagerController.java 
 * @Author:IL Clown   
 * @Date:2020年8月20日 上午9:29:23     
 */
package com.situ.shopsystem.controller;

import java.io.Serializable;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.shopsystem.pojo.Catalog;
import com.situ.shopsystem.pojo.LayuiResult;
import com.situ.shopsystem.service.CatalogService;

/** 
 * @ClassName:CatalogManagerController 
 * @Description:(这里用一句话描述这个类的作用)  
 * 
 * manager/catalog/delete
 * 
 * 
 * 
 */
@Controller
@RequestMapping("/manager/catalog/")
public class CatalogManagerController implements Serializable {
	private static final long serialVersionUID = 1L;

	@Autowired
	private CatalogService catalogService;

	@RequestMapping("showIndex")
	public String showIndex() {
		return "manager/catalog/catalog_index";
	}

	@RequestMapping("showAddOrUpdate")
	public String showAddOrUpdate() {
		return "manager/catalog/catalog_add_edit";
	}

	@ResponseBody
	@RequestMapping("findAllCatalog")
	public LayuiResult findAllCatalog(LayuiResult layuiResult) {
		layuiResult.setCode(0);
		layuiResult.setCount(catalogService.findCount());
		layuiResult.setData(catalogService.findAll());
		return layuiResult;
	}

	@ResponseBody
	@RequestMapping("doAddOrUpdate")
	public int doAddOrUpdate(Catalog catalog, HttpSession session) {
		if (catalog.getRowId() == null) {
			return catalogService.save(catalog, session);
		} else {
			return catalogService.update(catalog, session);
		}

	}

	@ResponseBody
	@RequestMapping("delete")
	public int delete(Long rowId) {
		return catalogService.delete(rowId);
	}

}
